package com.ruoyi.pingjiao.controller;

import java.util.List;
import javax.servlet.http.HttpServletResponse;

import com.ruoyi.pingjiao.domain.Teacher;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;
import com.ruoyi.common.annotation.Log;
import com.ruoyi.common.core.controller.BaseController;
import com.ruoyi.common.core.domain.AjaxResult;
import com.ruoyi.common.enums.BusinessType;
import com.ruoyi.pingjiao.domain.Courseclass;
import com.ruoyi.pingjiao.service.ICourseclassService;
import com.ruoyi.common.utils.poi.ExcelUtil;
import com.ruoyi.common.core.page.TableDataInfo;

/**
 * 上课班级管理Controller
 * 
 * @author 胡浩鹏
 * @date 2022-10-20
 */
@RestController
@RequestMapping("/score/courseclass")
public class CourseclassController extends BaseController
{
    @Autowired
    private ICourseclassService courseclassService;

    /**
     * 查询上课班级管理列表
     */
    @PreAuthorize("@ss.hasPermi('score:courseclass:list')")
    @GetMapping("/list")
    public TableDataInfo list(Courseclass courseclass,Teacher teacher)
    {
        courseclass.setTeacher(teacher);
        startPage();
//        List<Courseclass> list = courseclassService.selectCourseclassList(courseclass);
        List<Courseclass> list = courseclassService.selectCourseclassList(courseclass);
        return getDataTable(list);
    }

    /**
     * 导出上课班级管理列表
     */
    @PreAuthorize("@ss.hasPermi('score:courseclass:export')")
    @Log(title = "上课班级管理", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, Courseclass courseclass)
    {
        List<Courseclass> list = courseclassService.selectCourseclassList(courseclass);
        ExcelUtil<Courseclass> util = new ExcelUtil<Courseclass>(Courseclass.class);
        util.exportExcel(response, list, "上课班级管理数据");
    }

    /**
     * 获取上课班级管理详细信息
     */
    @PreAuthorize("@ss.hasPermi('score:courseclass:query')")
    @GetMapping(value = "/{courseclassId}")
    public AjaxResult getInfo(@PathVariable("courseclassId") Long courseclassId)
    {
        return AjaxResult.success(courseclassService.selectCourseclassByCourseclassId(courseclassId));
    }

    @PreAuthorize("@ss.hasPermi('score:courseclass:query')")
    @GetMapping(value = "/s/{courseclassId}")
    public AjaxResult getInfo1(@PathVariable("courseclassId") Long courseclassId)
    {
        return AjaxResult.success(courseclassService.selectCourseclassByCourseclassIdplus(courseclassId));
    }

    /**
     * 新增上课班级管理
     */
    @PreAuthorize("@ss.hasPermi('score:courseclass:add')")
    @Log(title = "上课班级管理", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody Courseclass courseclass)
    {
        return toAjax(courseclassService.insertCourseclass(courseclass));
    }

    /**
     * 修改上课班级管理
     */
    @PreAuthorize("@ss.hasPermi('score:courseclass:edit')")
    @Log(title = "上课班级管理", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody Courseclass courseclass)
    {
        System.out.println(courseclass);
        for (Teacher t : courseclass.getTeacherList()){
            System.out.println(t);
        }
        return toAjax(courseclassService.updateCourseclass(courseclass));
    }

    /**
     * 删除上课班级管理
     */
    @PreAuthorize("@ss.hasPermi('score:courseclass:remove')")
    @Log(title = "上课班级管理", businessType = BusinessType.DELETE)
	@DeleteMapping("/{courseclassIds}")
    public AjaxResult remove(@PathVariable Long[] courseclassIds)
    {
        return toAjax(courseclassService.deleteCourseclassByCourseclassIds(courseclassIds));
    }

    @GetMapping("course/{userId}")
    public AjaxResult getPjInfo(@PathVariable Long userId){
        return AjaxResult.success(courseclassService.getPjInfoByUserId(userId));
    }
}
